package edu.hunau.cxb19.oop.class30;

import java.time.LocalDateTime;

/**
 *
 * @author hb
 *
 *         2020-04-14 15:44:50
 */
public class ThreadInterruptTest {

	public static void main(String[] args) throws InterruptedException {
		Thread t1 = new Thread(() -> {
			for (int i = 0; i < 10; i++) {
				System.out.println(Thread.currentThread().getName() + " ]:i=" + i + ":" + LocalDateTime.now());
				if (i == 3) {
					try {
						// 当前的线程休眠5s
						Thread.sleep(5000);
					} catch (InterruptedException e) {
						System.out.println("中断成功....");
					}
				}
			}
		}, "my-thread-01");

		t1.start();

		Thread.sleep(3000);
		t1.interrupt();// 在main线程中中断t1线程的休眠状态

	}
}
